package com.eshipenet.shipnet.shiprpc.util;

import com.eshipenet.shipnet.ship.grpc.*;

import javax.cache.Cache;

public class BuilderUtil {


    public static ShipGovernorEdge shipGovernorEdgeBuilder(Cache.Entry<String, com.eshipenet.shipnet.ship.ShipGovernor> p){

        return ShipGovernorEdge.newBuilder().setNode(ShipGovernor
                .newBuilder()
                .setId(p.getKey())
                .setName(p.getValue().getName())
                .setCreatedAt(TimestampToDate.dateTotimestamp(
                        p.getValue().getCreatedAt()))
                .setUpdatedAt(TimestampToDate.dateTotimestamp(
                        p.getValue().getUpdatedAt()))
                .setInfo(GetJObjectUtil.getData(
                        p.getValue().getInfo()))
                .setAvatar(p.getValue().getAvatar())
                .setDesc(p.getValue().getDescription()))
                .setCursor(p.getValue().getId())
                .build();
    }


    public static ShipOwnerEdge shipOwnerEdgeBuilder(Cache.Entry<String, com.eshipenet.shipnet.ship.ShipOwner> p){

        return ShipOwnerEdge.newBuilder().setNode(ShipOwner
                .newBuilder()
                .setId(p.getKey())
                .setName(p.getValue().getName())
                .setCreatedAt(TimestampToDate.dateTotimestamp(
                        p.getValue().getCreatedAt()))
                .setUpdatedAt(TimestampToDate.dateTotimestamp(
                        p.getValue().getUpdatedAt()))
                .setInfo(GetJObjectUtil.getData(
                        p.getValue().getInfo()))
                .setAvatar(p.getValue().getAvatar())
                .setDesc(p.getValue().getDescription()))
                .setCursor(p.getValue().getId())
                .build();
    }


    public static ShipEdge shipEdgeBuilder(Cache.Entry<String, com.eshipenet.shipnet.ship.Ship> p){

        return ShipEdge.newBuilder().setNode(Ship
                .newBuilder()
                .setId(p.getKey())
                .setName(p.getValue().getName())
                .setCreatedAt(TimestampToDate.dateTotimestamp(
                        p.getValue().getCreatedAt()))
                .setUpdatedAt(TimestampToDate.dateTotimestamp(
                        p.getValue().getUpdatedAt()))
                .setInfo(GetJObjectUtil.getData(
                        p.getValue().getInfo()))
                .setAvatar(p.getValue().getAvatar())
                .setDesc(p.getValue().getDescription())
                .setOwnerId(p.getValue().getOwnerId())
                .setMmsi(p.getValue().getMmsi()))
                .setCursor(p.getValue().getId()).build();
    }


    public static ShipGovernorLinkEdge shipGovernorLinkEdgeBuilder(Cache.Entry<String, com.eshipenet.shipnet.ship.ShipGovernorLink> p){

        return ShipGovernorLinkEdge.newBuilder().setNode(ShipGovernorLink
                .newBuilder()
                .setShipId(p.getValue().getShipId())
                .setShipGovernorId(p.getValue().getShipGovernorId())
                .setCreatedAt(TimestampToDate.dateTotimestamp(
                        p.getValue().getCreatedAt()))
                .setUpdatedAt(TimestampToDate.dateTotimestamp(
                        p.getValue().getUpdatedAt())))
                .setCursor(p.getKey())
                .build();
    }

}
